package com.qys.livesMall.anchor.constants.enums;

import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.common.utils.MessageUtils;

public enum AnchorSellTaskStatus {
    待开播((byte) 0, "主播带货任务待开播", "待开播", "To be launched"),
    进行中((byte) 1, "主播带货任务进行中", "进行中", "Under way"),
    待结算((byte) 2, "主播带货任务待结算", "待结算", "To be settled"),
    已完成((byte) 3, "主播带货任务已完成", "已完成", "Completed"),
    未申请((byte) 4, "主播带货任务未申请开播", "未申请开播", "Not apply launched"),
    未通过((byte) 5, "主播带货任务未通过", "未通过申请", "Rejected application");


    private Byte status;
    private String error;
    private String zhInfo;
    private String enInfo;

    AnchorSellTaskStatus(Byte status, String error, String zhInfo, String enInfo) {
        this.status = status;
        this.error = error;
        this.zhInfo = zhInfo;
        this.enInfo = enInfo;
    }

    public Byte getStatus() {
        return status;
    }
    public String getError() {
        return MessageUtils.message(error);
    }
    public String getZhInfo() {
        return zhInfo;
    }
    public String getEnInfo() {
        return enInfo;
    }


    public static String getStatusErrorByType(Byte status) {
        AnchorSellTaskStatus sellTaskStatus = getByType(status);
        return null == sellTaskStatus ? null : sellTaskStatus.getError();
    }

    public static AnchorSellTaskStatus getByType(Byte status) {
        for (AnchorSellTaskStatus anchorSellTaskStatus : values()) {
            if (anchorSellTaskStatus.getStatus().equals(status)) {
                return anchorSellTaskStatus;
            }
        }
        return null;
    }


    /**
     * nowStatus:当前状态
     * args:需要满足的状态
     */
    public static void checkStatus(Byte nowStatus, AnchorSellTaskStatus... args) {
        if (null == nowStatus) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        for (AnchorSellTaskStatus s : args) {
            if (nowStatus.equals(s.getStatus())) {
                return;
            }
        }
        throw new QysException(getStatusErrorByType(nowStatus));
    }


    /**
     * 判断状态是否存在
     */
    public static AnchorSellTaskStatus statusExists(Byte status) {
        if (null == status) {
            throw new QysException(ExceptionEnum.INTERNAL_SERVER_ERROR);
        }
        AnchorSellTaskStatus sellTaskStatus = getByType(status);
        if (null == sellTaskStatus) {
            throw new QysException(MessageUtils.message("主播带货任务状态错误", status));
        }
        return sellTaskStatus;
    }
}
